package org.howie.dao;

import org.howie.entity.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class OrderDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public void addOrder(Order order) {
        String sql = "INSERT INTO tb_order(user_id, book_id, order_time, price) VALUES(?, ?, ?, ?)";
        jdbcTemplate.update(sql, order.getUserId(), order.getBookId(), order.getOrderTime(), order.getPrice());
    }

    public List<Order> getOrderList() {
        String sql = "SELECT * FROM tb_order";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(Order.class));
    }
}
